version 18.5
set scheme plottig

****************
*** Analysis ***
****************

*Load dataset
use data_wide, clear

* DROP ALL WITH LOW-COMPREHENSION
* Keeps only respondents who passed all comprehension checks (wlc_p_4)
keep if wlc_p_4

**# 1. Introduction
* Analyze average conditional gift (ACG) by region (Austria, DE-West, DE-East)
tabstat acgm, by(psys)

* Regress ACG on region to assess regional differences in giving behavior
reg acgm i.psys

* Calculate mean giving for each region (psys = 0, 1, 2 represent Austria, DE-West, DE-East)
margins, at(psys = (0 1 2))



**# 3. Methods and Data

* N per party system
tab psys

* Party Left-Right Scores by party support
preserve
collapse (mean) lrpart, by(partyabbrev)
sort lrpart
list
restore

* Table Voting Intention excluding non-voters and invalid voters
*Table excluding those who claimed they would not vote (8) and vote invalid (9) from the tabulation. This way, the percentages add up to 100 % as with the polls we compare the voting intentions to.
tab svy_65_at if ! inlist(svy_65_at, 8,9)
* The same in West-Germany
tab svy_65_de if !inlist(svy_65_de, 8,9) & psys == 1
* The same in East-Germany
tab svy_65_de if !inlist(svy_65_de, 8,9) & psys == 2

* Summarize left-right self-placement (lrpers) by region (psys)
tabstat lrpers, by(psys) stat (mean sd)


**# 4. Results
* Display the distribution of participants across political systems (psys: Austria, DE-West, DE-East)
tab psys

* Empirics I – "Prereg Graphically"
* Analyze average conditional gift by left-right position of preferred party
* Collapse the data to calculate the mean ACG, standard error (SE), and the number of parties for each region and party abbreviation
preserve
collapse (mean) acgm lrpart (sem) se_acgm=acgm (count) nparty=lrpart, by(psys partyabbrev)

* Generate 95% confidence intervals for ACG based on the standard error
gen ci_upper = acgm + 1.96 * se_acgm
gen ci_lower = acgm - 1.96 * se_acgm

* Sort data by left-right position for plotting
sort lrpart

* Plot average conditional gift by left-right position of preferred party, with fitted line and party labels
twoway (scatter acgm lrpart, mlabel(partyabbrev) mlabsize(medsmall) legend(off) mlabp(2)) ///
(lfit acgm lrpart [fweight=nparty], lwidth(.5) legend(off)) || , by(psys, rows(1)) ///
name(g3, replace) legend(off) ///
xtitle("Preferred Party's Left-Right Position") yscale(r(0 40)) ytitle("Average ACG") ///
graphregion(color(white)) plotregion(color(white)) note("")
restore

* Save the graph and export as PNG for use in publication
graph save "lrparty-scatterplot.gph", replace
graph export "lrparty-scatterplot.png", replace height(1500)

*Plot average conditional gift by participants' left-right self-placement, with jitter to avoid overlapping points, and fitted line
graph twoway scatter acgm lrpers, jitter(2.5) msize(0.4) ///
|| lfit acgm lrpers, lwidth(.5) || , by(psys, rows(1)) name(g3, replace) ///
  xtitle("Left-Right Self-Placement") ytitle("Average ACG") ///
graphregion(color(white)) plotregion(color(white)) ///
legend(off) note("")

* Save the graph and export as PNG for use in publication
graph save "lrpers-scatterplot.gph", replace
graph export "lrpers-scatterplot.png", replace height(1500)


* EMPIRICS II – "Prereg Analytically and Announced Robustness Check"
* Regress ACGM on treatment, party left-right position, and control variables to generate variable to keep a constant sample across models based on available observations
regress acgm i.psys i.treat lrpart i.agecat2 i.educat i.fem lincome
generate useobpart = e(sample)
tab useobpart psys

* Regress ACGM on treatment, left-right self-placement, and control variables to generate variable to keep a constant sample across models based on available observations
regress acgm i.psys i.treat lrpers i.agecat2 i.educat i.fem lincome
generate useobpers = e(sample) 


*** MODELS WITH PARTY'S LEFT-RIGHT POSITION
* Model 1: Treatment and Party-Left-Right position effect on ACGM without controls (except for experiment)
eststo m1: regress acgm i.treat i.psys lrpart if useobpart == 1, robust

* Model 2: Adding control variables for demographic factors
eststo m2: regress acgm i.treat i.psys lrpart i.agecat2 i.educat i.fem lincome if useobpart == 1, robust
vif  // Check for multicollinearity

* Model 3: Including interaction between region and party left-right position
eststo m3: regress acgm i.treat i.psys##c.lrpart i.agecat2 i.educat i.fem lincome if useobpart == 1, robust
* Marginal effects of left-right position by region
margins, dydx(lrpart) at(psys = (0 1 2))

* Plot marginal effects with confidence intervals and custom labels
marginsplot, yline(0) name(lrpartm, replace) yscale(r(5 -45)) ylabel(#6) ///
title("Marginal Effect of" "Preferred Party's Left-Right Position" "by Region") ///
xtitle(Region) graphregion(margin(large)) scale(1.2) plotregion(color(white))

* Save and export plot
graph save "MarginalEffectModel3.gph", replace
graph export "MarginalEffectModel3.png", replace height(1500)

* Nested regression: compare baseline model with model with interaction terms
nestreg: regress acgm (i.treat i.psys c.lrpart i.agecat2 i.educat i.fem lincome) (i.psys#c.lrpart) if useobpart == 1

* Export regression results in RTF format for publication
esttab m1 m2 m3 using "models123", rtf replace b(2) p(2) r2 ar2 aic obslast label mtitles("Model 1" "Model 2" "Model 3")


*** MODELS WITH LEFT-RIGHT SELF-PLACEMENT
* Model 4 like Model 1 with left-right self-placement (lrpers) instead of party left-right
eststo m4: regress acgm i.treat i.psys lrpers if useobpers == 1, robust

* Model 5: Adding demographic control variables
eststo m5: regress acgm i.treat i.psys lrpers i.agecat2 i.educat i.fem lincome if useobpers == 1, robust
vif  // Check for multicollinearity

* Model 6: Interaction between region and left-right self-placement
eststo m6: regress acgm i.treat i.psys##c.lrpers i.agecat2 i.educat i.fem lincome if useobpers == 1, robust

* Marginal effects of left-right self-placement by region
margins, dydx(lrpers) at(psys = (0 1 2))

* Plot marginal effects with confidence intervals
marginsplot, yline(0) name(lrpersm, replace) yscale(r(5 -45)) ylabel(#6) ///
title("Marginal Effect of" "Left-Right Self-Placement" "by Region") ///
xtitle(Region) graphregion(margin(large)) scale(1.2)  ///
graphregion(color(white)) plotregion(color(white)) ///
legend(off) note("")

* Save and export plot
graph save "MarginalEffectModel6.gph", replace
graph export "MarginalEffectModel6.png", replace height(1500)

* Region-specific regressions for East Germany (psys == 2) to get variance explained
regress acgm i.treat c.lrpers i.agecat2 i.educat i.fem lincome if useobpers == 1 & psys == 2, robust 
* Nested regression to compare models without and with left-right self-placement
nestreg: regress acgm (i.treat i.agecat2 i.educat i.fem lincome) (c.lrpers) if useobpers == 1 & psys == 2, robust


* Nested regression with interaction effects
nestreg: regress acgm (i.treat i.psys c.lrpers i.agecat2 i.educat i.fem lincome) (i.psys#c.lrpers) if useobpers == 1

* Export regression results for Models 4, 5, and 6
esttab m4 m5 m6 using "models456", rtf replace b(2) p(2) r2 ar2 aic obslast label mtitles("Model 4" "Model 5" "Model 6")



**# EMPIRICS III: EXPLORATORY ANALYSIS
* Social Trust: Calculate Cronbach's Alpha only for those with the full comprehension
alpha svy_9 svy_10 svy_11

* Economic Orientation: Calculate Cronbach's Alpha only for those with the full comprehension
alpha svy_1 svy_2 svy_3


* Correlations between left-right placement, trust, and orientation measures
pwcorr lrpers soctrst cult cults econ econs

* Regress ACGM on treatment, left-right self-placement, economic, cultural orientations, and social trust and demographic control variables to get variable for consistent samples
regress acgm i.treat lrpers econs cults soctrst i.agecat i.educat i.fem lincome
gen useobexp = e(sample)

* Model 7: Social trust effects
eststo m7: regress acgm i.treat i.psys c.lrpers soctrst econs cults i.agecat2 i.educat i.fem lincome if useobexp == 1, robust
vif

* Model 8: Economic  orientations effects
eststo m8: regress acgm i.treat i.psys econs i.agecat2 i.educat i.fem lincome if useobexp == 1, robust

* Model 9: Interaction of region and economic orientation
eststo m9: regress acgm i.treat i.psys##c.econs i.agecat2 i.educat i.fem lincome if useobexp == 1, robust
* Marginal effects by region
margins, dydx(econs) at(psys = (0 1 2))
* Plot marginal effects with confidence intervals
marginsplot, yline(0) name(lrexlpom, replace) yscale(r(5 -45)) ylabel(#6) ///
xtitle(Region) graphregion(margin(large)) plotregion(color(white)) scale(1.2)

* Model 10: Cultural orientations effects
eststo m10a: regress acgm i.treat i.psys cults i.agecat2 i.educat i.fem lincome if useobexp == 1, robust

* Model 11: Interaction of region and cultural orientation
eststo m11a: regress acgm i.treat i.psys##c.cults i.agecat2 i.educat i.fem lincome if useobexp == 1, robust

* Model 12: Interaction of region and left-right self-placement, controlling for trust and orientations
eststo m12a: regress acgm i.treat i.psys##c.soctrst i.psys##c.lrpers i.psys##c.econs i.psys##c.cults i.agecat2 i.educat i.fem lincome if useobexp == 1, robust

* Marginal effects by region
margins, dydx(lrpers) at(psys = (0 1 2))

* Plot marginal effects with confidence intervals
marginsplot, yline(0) name(lrexlpom, replace) yscale(r(5 -45)) ylabel(#6) ///
xtitle(Region) graphregion(margin(large)) plotregion(color(white)) scale(1.2)

* Save and export plot
graph save "MarginalEffectModel12.gph", replace
graph export "MarginalEffectModel12.png", replace height(1500)

* Export regression results for Models 7, 8, 9, and 10
esttab m7a m8a m9a m10a m11a m12a using "models789101112", rtf replace b(2) p(2) r2 ar2 aic obslast label mtitles("Model 7" "Model 8" "Model 9" "Model 10" "Model 11" "Model 12")
